import 'package:factoryside/api/api.dart';
import 'package:factoryside/utils/ColorsUtils.dart';
import 'package:factoryside/utils/request_util.dart';
import 'package:factoryside/utils/utils.dart';
import 'package:factoryside/home/page_bill.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'page_recharge.dart';

class WalletPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _WalletState();
  }
}

class _WalletState extends State<WalletPage> {
  var _refreshController=RefreshController();

  @override
  void dispose() {
    super.dispose();
  }
  var walletInfo;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getWalletInfo();
  }

  void getWalletInfo() {
    RequestUtil.post(Api.getFactorySummaryOfFunds, {
      'UserID':Api.userName
    }).then((value) {
      setState(() {
        walletInfo=value['Data']['msg'];
      });
    });
  }
  void _onRefresh() async {
    await Future.delayed(Duration(milliseconds: 1000));
    getWalletInfo();
    _refreshController.refreshCompleted();
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: buildAppBar('我的钱包',null,context),
        body: walletInfo==null?Center(child: CircularProgressIndicator(),):SmartRefresher(
          enablePullDown: true,
          controller: _refreshController,
          onRefresh: _onRefresh,
          child: buildBody(),
        ));
  }
  Widget buildBody(){
    return ListView(children: [
      Container(
          padding: EdgeInsets.fromLTRB(30, 30, 30, 20),
          color: Colors.white,
          child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('我的余额（元）'),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(
                      '${walletInfo['Balance']}',
                      style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
                    ),
                  ],
                ),
                Container(
                  margin: EdgeInsets.only(top: 20),
                  child: Row(
                    children: [
                      InkWell(
                        onTap: (){
                          Navigator.push(this.context, CupertinoPageRoute(
                              builder: (BuildContext context) {
//                                  return ShowCase();
                                return RechargePage();
                              })).then((value){
//                              if(value!=null){
//                                MineService.getWalletInfo().then((value){
//                                  setState(() {
//                                    walletInfo=value.data.data;
//                                  });
//                                });
//                              }
                          });
                        },
                        child: Container(
                            padding: EdgeInsets.symmetric(horizontal: 20),
                            height: 36,
                            decoration: BoxDecoration(
                                color: Colors.white,
                                border: Border.all(color: ColorsUtil.hexToColor('#b4b4b4'),width: 0.3),
                                borderRadius: BorderRadius.all(Radius.circular(18))),
                            child: Row(
                              children: [
                                Image.asset(
                                  'assets/money.png',
                                  width: 15,
                                  height: 15,
                                ),
                                Container(
                                  margin: EdgeInsets.only(left: 10),
                                  child: Text(
                                    '充值',
                                    style: TextStyle(
                                        fontSize: 12,
                                        fontWeight: FontWeight.bold),
                                  ),
                                ),
                              ],
                            )
                        ),
                      ),
                      InkWell(
                        onTap: (){
//                          showToast('待开发...');
                          push(context, BillPage());
//                            Navigator.push(this.context, CupertinoPageRoute(
//                                builder: (BuildContext context) {
//                                  return WithDrawPage(walletInfo);
//                                })).then((value){
//                              if(value!=null){
//                                MineService.getWalletInfo().then((value){
//                                  setState(() {
//                                    walletInfo=value.data.data;
//                                  });
//                                });
//                              }
//                            });
                        },
                        child: Container(
                            padding: EdgeInsets.symmetric(horizontal: 20),
                            height: 36,
                            decoration: BoxDecoration(
                                color: Colors.white,
                                border: Border.all(color: ColorsUtil.hexToColor('#b4b4b4'),width: 0.3),
                                borderRadius: BorderRadius.all(Radius.circular(18))),
                            child: Row(
                              children: [
                                Image.asset(
                                  'assets/asd.png',
                                  width: 15,
                                  height: 15,
                                ),
                                Container(
                                  margin: EdgeInsets.only(left: 10),
                                  child: Text(
                                    '明细',
                                    style: TextStyle(
                                        fontSize: 12,
                                        fontWeight: FontWeight.bold),
                                  ),
                                ),
                              ],
                            )
                        ),
                      ),
                    ],
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  ),
                )
              ])),
//        GestureDetector(
//          child: Container(
//            margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
//            color: Colors.white,
//            padding: EdgeInsets.symmetric(horizontal: 20),
//            height: 50,
//            child: Row(
//              children: [
//                Container(
//                    padding: EdgeInsets.symmetric(horizontal: 10),
//                    child: Image.asset(
//                      'assets/asd.png',
//                      width: 20,
//                      height: 20,
//                    )),
//                Expanded(child: Text('我的银行卡')),
//                Image.asset(
//                  'assets/right.png',
//                  width: 20,
//                  height: 20,
//                ),
//              ],
//            ),
//          ),
//          onTap: () {
////            Navigator.push(this.context, CupertinoPageRoute(
////                builder: (BuildContext context) {
////                  return CardPage(false);
////                }));
//          },
//        ),
//      GestureDetector(
//        child: Container(
//          color: Colors.white,
//          padding: EdgeInsets.symmetric(horizontal: 20),
//          height: 50,
//          child: Row(
//            children: [
//              Container(
//                  padding: EdgeInsets.symmetric(horizontal: 10),
//                  child: Image.asset(
//                    'assets/money.png',
//                    width: 20,
//                    height: 20,
//                  )),
//              Expanded(child: Text('收支明细')),
//              Image.asset(
//                'assets/right.png',
//                width: 20,
//                height: 20,
//              ),
//            ],
//          ),
//        ),
//        onTap: () {
////            Navigator.push(this.context, CupertinoPageRoute(
////                builder: (BuildContext context) {
////                  return BillPage();
////                }));
//        },
//      ),
//      Divider(height: 0.5,),
      Container(
        color: Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 20),
        height: 50,
        child: Row(
          children: [
            Container(
                padding: EdgeInsets.symmetric(horizontal: 10),
                child: Image.asset(
                  'assets/组 846.png',
                  width: 20,
                  height: 20,
                )),
            Expanded(child: Text('进行中暂冻结')),
            Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('￥${walletInfo['Frozen']}')
              ],
            ),
          ],
        ),
      ),
      Divider(height: 0.5,),
      Container(
        color: Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 20),
        height: 50,
        child: Row(
          children: [
            Container(
                padding: EdgeInsets.symmetric(horizontal: 10),
                child: Image.asset(
                  'assets/组sdfyh.png',
                  width: 20,
                  height: 20,
                )),
            Expanded(child: Text('已完结金额')),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('￥${walletInfo['Settled']}'),
              ],
            ),
          ],
        ),
      ),
      Divider(height: 0.5,),
      Container(
        color: Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 20),
        height: 50,
        child: Row(
          children: [
            Container(
                padding: EdgeInsets.symmetric(horizontal: 10),
                child: Image.asset(
                  'assets/组 849.png',
                  width: 20,
                  height: 20,
                )),
            Expanded(child: Text('保证金')),
            Text('￥${walletInfo['Deposit']}'),
          ],
        ),
      ),
      Divider(height: 0.5,),
      Container(
        color: Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 20),
        height: 50,
        child: Row(
          children: [
            Container(
                padding: EdgeInsets.symmetric(horizontal: 10),
                child: Image.asset(
                  'assets/组 849.png',
                  width: 20,
                  height: 20,
                )),
            Expanded(child: Text('总充值')),
            Text('￥${walletInfo['TotalRecharge']}'),
          ],
        ),
      ),
    ]);
  }
}
